home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3789 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.1 KB  |  34 lines

  1. Path: news.walrus.com!news
  2. From: fjordao@walrus.com (Felipe Jordao)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: [Q] Converting dates in MMYY to YYMMDD format
  5. Date: Fri, 26 Jan 1996 03:14:54 GMT
  6. Organization: HAC
  7. Message-ID: <4e9h1h$kr7@walrus2.walrus.com>
  8. References: <4e6ms8$ad5@walrus2.walrus.com> <3107B2BE.794B@vnet.ibm.com>
  9. NNTP-Posting-Host: p19.ts1.walrus.com
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. Philip Staite <pstaite@vnet.ibm.com> wrote:
  13.  : Your example output looks like YYMMDD not DDMMYY...  Anyway, try this:
  14.  
  15. Actually, my mistake, it's YYMMDD that I want.  I came up with the
  16. same logic that you did but not quite as concise, thanks for the tip.
  17. One thing that's missing though is if we're in 96 feb has 29 days not
  18. 28.  What I did was use a switch statement for the dates and then
  19. tested for a leap year there.
  20.  
  21. Felipe
  22.  
  23.  : #include<iostream.h>   
  24.  : long mn[ 12 ] = { 31, 28, 31, 30, 31, 30,
  25.  :                   31, 31, 30, 31, 30, 31 };
  26.  : int main() {
  27.  :     long n;
  28.  :     cin >> n;  // get date
  29.  :     cout << ( mn[ n / 100 - 1 ] + ( n / 100 ) * 100 + ( n % 100 ) *
  30.  : 10000 ) << endl;
  31.  :     return 0; }
  32.  
  33.  
  34.